package xyz.zhzby.cyzx.oj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import xyz.zhzby.cyzx.oj.entity.Language;
import xyz.zhzby.cyzx.oj.mapper.LanguageMapper;
import xyz.zhzby.cyzx.oj.service.ILanguageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xyz.zhzby.cyzx.servicebase.exception.BusinessException;

/**
 * <p>
 * 编程语言 服务实现类
 * </p>
 *
 * @author zby
 * @since 2021-12-26
 */
@Service
@Slf4j
public class LanguageServiceImpl extends ServiceImpl<LanguageMapper, Language> implements ILanguageService {

    @Override
    public Long getLanIdByName(String lanName) {
        LambdaQueryWrapper<Language> qw = new LambdaQueryWrapper<>();
        qw.eq(Language::getName, lanName);
        Language language = baseMapper.selectOne(qw);
        if (language != null) {
            return language.getId();
        }
        log.error("根据语言名{}查询语言为空", lanName);
        throw new BusinessException("出现未知错误，请重试");
    }

}
